package com.yichi.util;

import com.yichi.device_bean.BatteryStore;
import com.yichi.device_bean.BatteryStoreType;
import com.yichi.device_bean.BmsParam;
import com.yichi.device_bean.BmsStatus;

public class BeanUtil {

    /**
     * 置空电池仓数据
     * 变为没电池状态
     */
    public static void setBatteryStoreEmpty(BatteryStore batteryStore) {
        batteryStore.setHasBattery(false);
        batteryStore.setBatteryNo("");
        batteryStore.setLockStatus(0);
        batteryStore.setBatterySoc(null);
        batteryStore.setBatteryMileage(null);
        batteryStore.setBmsParam(null);
        batteryStore.setBmsStatus(null);
    }

    //拷贝BmsParam
    public static void copyBmsParam(BmsParam source, BmsParam target) {
        if (source != null && target != null) {
            target.setBatteryNo(source.getBatteryNo());
            target.setTotalVoltage(source.getTotalVoltage());
            target.setSoc(source.getSoc());
            target.setSoh(source.getSoh());
            target.setCellHighVoltage(source.getCellHighVoltage());
            target.setCellLowVoltage(source.getCellLowVoltage());
            target.setRechargeCurrent(source.getRechargeCurrent());
            target.setEnvTemp(source.getEnvTemp());
            target.setCellTemp(source.getCellTemp());
        }
    }

    //拷贝BmsStatus
    public static void copyBmsStatus(BmsStatus source, BmsStatus target) {
        if (source != null && target != null) {
            target.setMosFDSH(source.getMosFDSH());
            target.setMosCDSH(source.getMosCDSH());
            target.setCddwbh(source.getCddwbh());
            target.setCdgwbh(source.getCdgwbh());
            target.setCdgl(source.getCdgl());
            target.setDxycgd(source.getDxycgd());
            target.setCdzt(source.getCdzt());
        }
    }

    /**
     * 拷贝电池仓数据
     * @param src
     * @param tar
     */
    public static void copyBatteryStore(BatteryStore src, BatteryStore tar) {
        if (src == null || tar == null) {
            return;
        }

//        tar.setStoreType(src.getStoreType());//必须清除
        tar.setHasBattery(src.getHasBattery());
        tar.setBatteryNo(src.getBatteryNo());
        tar.setDoorOpen(src.getDoorOpen());
        tar.setBatterySoc(src.getBatterySoc());
        tar.setBatteryMileage(src.getBatteryMileage());
        tar.setLockStatus(src.getLockStatus());

        // 深拷贝 BmsParam
        if (src.getBmsParam() != null) {
            BmsParam newBmsParam = new BmsParam();
            newBmsParam.setBatteryNo(src.getBmsParam().getBatteryNo());
            newBmsParam.setTotalVoltage(src.getBmsParam().getTotalVoltage());
            newBmsParam.setSoc(src.getBmsParam().getSoc());
            newBmsParam.setSoh(src.getBmsParam().getSoh());
            newBmsParam.setCellHighVoltage(src.getBmsParam().getCellHighVoltage());
            newBmsParam.setCellLowVoltage(src.getBmsParam().getCellLowVoltage());
            newBmsParam.setRechargeCurrent(src.getBmsParam().getRechargeCurrent());
            newBmsParam.setEnvTemp(src.getBmsParam().getEnvTemp());
            newBmsParam.setCellTemp(src.getBmsParam().getCellTemp());
            tar.setBmsParam(newBmsParam);
        } else {
            tar.setBmsParam(null);
        }

        // 深拷贝 BmsStatus
        if (src.getBmsStatus() != null) {
            BmsStatus newBmsStatus = new BmsStatus();
            newBmsStatus.setMosFDSH(src.getBmsStatus().getMosFDSH());
            newBmsStatus.setMosCDSH(src.getBmsStatus().getMosCDSH());
            newBmsStatus.setCddwbh(src.getBmsStatus().getCddwbh());
            newBmsStatus.setCdgwbh(src.getBmsStatus().getCdgwbh());
            newBmsStatus.setCdgl(src.getBmsStatus().getCdgl());
            newBmsStatus.setDxycgd(src.getBmsStatus().getDxycgd());
            newBmsStatus.setCdzt(src.getBmsStatus().getCdzt());
            tar.setBmsStatus(newBmsStatus);
        } else {
            tar.setBmsStatus(null);
        }
    }

}
